import { HttpClient, HttpParams } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-network-table',
  templateUrl: './network-table.component.html',
  styleUrls: ['./network-table.component.less']
})
export class NetworkTableComponent implements OnInit {
  params = {
    page: 1,
    size: 10,
  };
  total=0;
  listOfData = [];
  constructor(private httpClient: HttpClient) {}

  ngOnInit(): void {
    this.getNetwork();
  }

  getNetwork() {
    let url = 'http://localhost:8080/api/mockDataNodePaging';
    let queryParams = new HttpParams();
    Object.keys(this.params).forEach((key) => {
      queryParams = queryParams.append(key, this.params[key]);
    });
    this.httpClient.get(url, { params: queryParams }).subscribe(
      (res:any) => {
        console.log('接口获取成功', res);
        if (res.code === 200) {
          this.listOfData = res.result.data;
          this.total = res.result.total;
        }
      },
      (err) => {
        console.log('接口获取失败', err);
      }
    );
  }

  tableChange(evt,type:string){
    if (type === "page") {
      this.params.page = evt;
    }else{
      this.params.size = evt;
    }

    this.getNetwork();
  }

}
